package cfdt.ldl.risk.service;

import cfdt.common.enums.CommonCodeEnum;
import cfdt.common.exception.CodeException;
import cfdt.common.vo.ObjectBaseResponse;
import cfdt.ldl.db.biz.WhiteIpListBiz;
import cfdt.ldl.core.entity.WhiteIpList;
import cfdt.ldl.risk.api.request.CheckBlacklistRiskRequest;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RiskService {

    private static final Logger logger = LoggerFactory.getLogger(RiskService.class);

    @Autowired
    private WhiteIpListBiz whiteIpListBiz;

    /**
     * 检查黑名单
     */
    public ObjectBaseResponse checkBlackList(CheckBlacklistRiskRequest request) {
        ObjectBaseResponse baseResponse = new ObjectBaseResponse();

        try {
            // 客户统一社会信用代码
            String usci = request.getUsci();
            // 客户统一社会信用代码
            String requestIp = request.getRequestIp();

            // 检查白名单
            int count = whiteIpListBiz.count(
                    new LambdaQueryWrapper<WhiteIpList>().eq(WhiteIpList::getIp, requestIp));
            if (count < 1) {
                throw new CodeException(CommonCodeEnum.CODE_0003);
            }

            // 检查统一信用代码黑名单
            // ...

        } catch (CodeException e) {
            baseResponse.setCode(e.getCode());
            baseResponse.setMessage(e.getMessage());
        } catch (Exception e) {
            logger.info("黑名单检查异常", e);
            baseResponse.setCode("2436");
            baseResponse.setMessage(e.getMessage());
        }
        return baseResponse;
    }


}
